package com.hd.tiyu.yuejian.Activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.hd.tiyu.yuejian.Adapter.PayAdapter;
import com.hd.tiyu.yuejian.JavaBean.Pay;
import com.hd.tiyu.yuejian.Model.UserModel;
import com.hd.tiyu.yuejian.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class PayActivity extends AppCompatActivity {
    private ImageView back;
    RecyclerView recyclerView;

    private SharedPreferences sp;
    private String userId;//为用户id
    private String clubId;
    private String sessionId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay);
        initViews();
        initData();
        initEvens();
    }

    private void initViews() {
        back=(ImageView)findViewById(R.id.img_dingdanback);
        recyclerView=(RecyclerView) findViewById(R.id.dingdanlist);
        recyclerView.setLayoutManager(new LinearLayoutManager(PayActivity.this));

        sp = getSharedPreferences("loginUser", Context.MODE_PRIVATE);
        clubId=getIntent().getStringExtra("Club_Id");
        userId=sp.getString("user_id","");
        sessionId=sp.getString("SessionID","");
    }

    private void initData() {
        UserModel usermodel=new UserModel();
        Call<List<Pay>> call=usermodel.getPay(userId,"0","1",sessionId);
        call.enqueue(new Callback<List<Pay>>() {
            @Override
            public void onResponse(Call<List<Pay>> call, Response<List<Pay>> response) {
                List<Pay> data=response.body();
                recyclerView.setAdapter(new PayAdapter(PayActivity.this,data));

            }

            @Override
            public void onFailure(Call<List<Pay>> call, Throwable t) {
                Toast.makeText(PayActivity.this,"获取列表失败",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initEvens() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

}
